package com.ms.pda.components

import android.content.Context
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.blankj.utilcode.util.AppUtils
import com.lxj.xpopup.core.CenterPopupView
import com.ms.pda.BR
import com.ms.pda.R

class UpdaterDialog(context: Context) : CenterPopupView(context) {

    var binding: ViewDataBinding? = null

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_updater
    }

    override fun onCreate() {
        super.onCreate()
        binding = DataBindingUtil.bind(popupImplView)
        binding?.setVariable(BR.progress, 0)
        binding?.setVariable(BR.listener, UpdaterDialogListener())
    }

    inner class UpdaterDialogListener {
        fun cancelUpdate(view: View) {
            AppUtils.exitApp()
        }
    }

    fun setProgress(progress: Int) {
        binding?.setVariable(BR.progress, progress)
        binding?.executePendingBindings()
    }

    override fun destroy() {
        super.destroy()
        binding?.unbind()
    }
}